package com.hzjy.api.controller;

import com.github.pagehelper.PageInfo;
import com.hzjy.api.service.BqTokenService;
import com.hzjy.api.service.impl.BqUserServiceImpl;
import com.hzjy.api.vo.BqLoginUser;
import com.hzjy.api.vo.BqUser;
import com.hzjy.common.constant.HttpStatus;
import com.hzjy.common.core.controller.BaseController;
import com.hzjy.common.core.domain.AjaxResult;
import com.hzjy.common.core.page.TableDataInfo;
import com.hzjy.common.utils.ServletUtils;
import com.hzjy.system.domain.SysNotice;
import com.hzjy.system.domain.vo.SysNoticeVO;
import com.hzjy.system.service.ISysNoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * 消息通知，公告
 */
@RestController
@RequestMapping("/api/notice")
public class NoticeController extends BaseController {

    @Autowired
    private ISysNoticeService noticeService;

    @Autowired
    private BqTokenService bqTokenService;

    /**
     * 消息公告，通知
     *
     * @param notice
     * @return
     */
    @GetMapping("/list")
    public TableDataInfo list(SysNotice notice) {
        BqLoginUser bqloginUser = bqTokenService.getBqLoginUser(ServletUtils.getRequest());
        if (bqloginUser != null) {
            BqUser bqUser = bqloginUser.getBqUser();
            Long userId = bqUser.getUserId();
            notice.setUserId(userId.toString());
        }
        startPage();
        List<SysNoticeVO> list = noticeService.selectNoticeList(notice);

        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(HttpStatus.SUCCESS);
        rspData.setMsg("查询成功");
        rspData.setRows(list);
        rspData.setTotal(list.size());
        return rspData;
    }
}
